#if !defined(AFX_FEEDTREE_H__D25009B7_1DC8_4CB2_A3A1_7EF7912AF597__INCLUDED_)
#define AFX_FEEDTREE_H__D25009B7_1DC8_4CB2_A3A1_7EF7912AF597__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// FeedTree.h : header file
//
#include "RSSFeed.h"
#include "FeedGroup.h"

/////////////////////////////////////////////////////////////////////////////
// CFeedTree window
struct TREE_NODE_PARAM
{
	TREE_NODE_PARAM(FeedGroup* pGroup){
		nType = GROUP;
		lParam = reinterpret_cast<LPARAM>(pGroup);
	}
	TREE_NODE_PARAM(RSSFeed* pFeed){
		nType = FEED;
		lParam = reinterpret_cast<LPARAM>(pFeed);
	}
	~TREE_NODE_PARAM(){
		if (nType == 1) {
			delete reinterpret_cast<RSSFeed*>(lParam);
		}else if(nType == GROUP){
			delete reinterpret_cast<FeedGroup*>(lParam);
		}
	}
	enum{
		FEED=1,
		GROUP=2
	} nType;
	LPARAM lParam;
};


class CFeedTree : public CTreeCtrl
{
	DECLARE_DYNAMIC(CFeedTree)
// Construction
public:
	CFeedTree();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CFeedTree)
	//}}AFX_VIRTUAL

// Implementation
public:
	void InitTree();

	FeedGroup* GetFeedGroup(HTREEITEM hItem){
		TREE_NODE_PARAM* pdata = reinterpret_cast<TREE_NODE_PARAM* >( GetItemData(hItem) );
		return pdata->nType == TREE_NODE_PARAM::GROUP ? reinterpret_cast<FeedGroup*>(pdata->lParam) : NULL;
	}
	RSSFeed* GetRSSFeed(HTREEITEM hItem){
		TREE_NODE_PARAM* pdata = reinterpret_cast<TREE_NODE_PARAM* >( GetItemData(hItem) );
		return pdata->nType == TREE_NODE_PARAM::FEED? reinterpret_cast<RSSFeed*>(pdata->lParam) : NULL;
	}

	HTREEITEM InsertAGroupToTree(FeedGroup* pGroup, HTREEITEM hParent = TVI_ROOT);
	HTREEITEM InsertAGroup(const char* name, const char* description, HTREEITEM hParent = TVI_ROOT);	
	bool InsertAFeed(const char* link, const char* title, HTREEITEM hParent = TVI_ROOT);
	HTREEITEM InsertAFeedToTree(RSSFeed* pFeed, HTREEITEM hParent = TVI_ROOT);
	virtual ~CFeedTree();

	// Generated message map functions
protected:
	//{{AFX_MSG(CFeedTree)	
	afx_msg void OnDeleteitem(NMHDR* pNMHDR, LRESULT* pResult);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnAddNewGroup();
	afx_msg void OnAddNewFeed();
	afx_msg void OnUpdateGroupOrFeed();
	afx_msg void OnDeleteGroupOrFeed();

private:

};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FEEDTREE_H__D25009B7_1DC8_4CB2_A3A1_7EF7912AF597__INCLUDED_)
